﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RsCms.Infrastructure
{
    public  class StrHelper
    {
        /// <summary>
        /// 创建拼音短语
        /// </summary>
        /// <param name="text"></param>
        /// <returns></returns>
        public static string CreateSlug(string text)
        {
            const string start = "/posts/";
            var str = text.ToCharArray();
            var target = start;
            foreach (var item in str)
            {
                string s = "";
                if (TinyPinyin.PinyinHelper.IsChinese(item))
                {
                    s = TinyPinyin.PinyinHelper.GetPinyin(item);
                }
                else
                {
                    s = item.ToString();
                }
                target += target == start ? s : $"-{s}";

            }

            return target;
        }
    }
}
